package com.example.yyang.demo.network

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

class ApiClient private constructor(){
    lateinit var service: GitHubService
    private var dev = "http://192.168.0.15"
    var pro = "https://api.github.com/"
    var url= this.pro
    private object Holder {
        val INSTANCE = ApiClient()
    }

    companion object {
        val instance by lazy { Holder.INSTANCE }
    }

    fun init(){
        val okHttpClient = OkHttpClient().newBuilder()
                .build()
        val retrofit = Retrofit.Builder()
                .baseUrl(url)   //本文以GitHub API为例
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(okHttpClient)
                .build()
        service = retrofit.create(GitHubService::class.java)
    }
}